//
// Created by v on 19-7-9.
//

#ifndef CUTEDEVICE_C600_CMCOAPBROADCAST_H
#define CUTEDEVICE_C600_CMCOAPBROADCAST_H

#include <iostream>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#ifdef WITH_COAP
#include <coap2/coap.h>
#endif

class CMCoapBroadcast
{
  public:
    CMCoapBroadcast(const char *addr, int port);
    virtual ~CMCoapBroadcast();

    void setDebug(bool d) { m_debug = d; }

    int sendData(const char *data, size_t len, const char *opt, int id = 0);

    int recvData(char **data, size_t *len, int *id);

  protected:
    int initSock();

  private:
    std::string m_sendData;
    std::string m_recvData;

    int                m_broadSock;
    struct sockaddr_in m_addrtoBroad;
    std::string        m_broadAddr;
    int                m_broadPort;

    bool m_debug;
};

#endif // CUTEDEVICE_C600_CMCOAPBROADCAST_H
